package com.alkaid.anime.controller;

import com.alkaid.anime.service.AnimeVideoService;
import com.alkaid.commons.controller.BaseController;
import com.alkaid.commons.entity.AnimeRefresh;
import com.alkaid.commons.entity.AnimeSource;
import com.alkaid.commons.entity.AnimeVideo;
import com.alkaid.commons.param.anime.AnimePlay;
import com.alkaid.commons.utils.JsonResult;
import org.springframework.web.bind.annotation.*;

import java.util.LinkedList;
import java.util.List;

/**
 * @author Kylin
 */
@RestController
@RequestMapping("api/anime")
public class AnimeVideoController extends BaseController {

    private final AnimeVideoService animeVideoService;

    public AnimeVideoController(AnimeVideoService animeVideoService) {
        this.animeVideoService = animeVideoService;
    }

    @GetMapping("/play/eq/{id}")
    public JsonResult<AnimePlay> getAnimePlayByVideoId(@PathVariable Integer id) {
        AnimePlay animePlay = animeVideoService.getAnimePlay(id);
        return new JsonResult<>(200, animePlay, "success");
    }

    @PostMapping("/play/get_source")
    public JsonResult<List<AnimeSource>> getSource(String jwt, Long id) {
        List<AnimeSource> animeSources = animeVideoService.getSource(jwt, id);
        return new JsonResult<>(200, animeSources, "success");
    }

    /**
     * 新番时间表
     *
     * @return the anime refresh list
     */
    @GetMapping("/get_refresh")
    public JsonResult<LinkedList<List<AnimeRefresh>>> getAnimeRefreshList() {
        return new JsonResult<>(200, animeVideoService.getAnimeRefreshLists(), "success");
    }

    /**
     * 最近更新
     *
     * @param num the num
     * @return the recent
     */
    @GetMapping("/recent/{num}")
    public JsonResult<List<AnimeVideo>> getRecent(@PathVariable Integer num) {
        List<AnimeVideo> animeVideos = animeVideoService.getAnimeVideos(num);
        return new JsonResult<>(200, animeVideos, "success");
    }
}
